package com.chixing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chixing.commons.ServerResponse;
import com.chixing.mapper.CompanyDetailMapper;
import com.chixing.pojo.CompanyDetail;
import com.chixing.pojo.InternshipExperience;
import com.chixing.mapper.InternshipExperienceMapper;
import com.chixing.service.IInternshipExperienceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 实习经历表 服务实现类
 * </p>
 *
 * @author Jason Marslyon
 * @since 2022-10-04
 */
@Service
public class InternshipExperienceServiceImpl extends ServiceImpl<InternshipExperienceMapper,InternshipExperience> implements IInternshipExperienceService {

    @Autowired(required = false)
    private InternshipExperienceMapper internshipExperienceMapper;
    @Autowired(required = false)
    private CompanyDetailMapper companyDetailMapper;

    @Override
    public InternshipExperience getInternshipById(Integer internshipId) {
        QueryWrapper wrapper = new QueryWrapper<>();
        wrapper.eq("internship_id",internshipId);
//        根据myresumeId查得结果
        List<InternshipExperience> internshipList = internshipExperienceMapper.selectList(wrapper);
        System.out.println("myserviceImpl-personAll>>>>>"+ internshipList.get(0));//获取list第一条信息
        InternshipExperience experience = internshipList.get(0);
        return experience;
    }

    @Override
    public CompanyDetail getCompanyById(Integer companyId) {
        CompanyDetail companyDetail = companyDetailMapper.selectById(companyId);
//        QueryWrapper wrapper = new QueryWrapper<>();
//        wrapper.eq("company_id",companyId);
////        根据companyId查得结果
//        List<CompanyDetail> companyDetails = companyDetailMapper.selectList(wrapper);
//        System.out.println("myserviceImpl-personAll>>>>>"+ companyDetails.get(0));//获取list第一条信息
//        CompanyDetail companyDetail = companyDetails.get(0);
        return companyDetail;
    }

    //    修改实习经历表
    @Override
    public ServerResponse updateInternshipById(InternshipExperience internshipExperience, Integer internshipId) {
        InternshipExperience internshipSql = internshipExperienceMapper.selectById(internshipId);

        internshipSql.setDepartmentName(internshipExperience.getDepartmentName());
        internshipSql.setJobName(internshipExperience.getJobName());
        internshipSql.setJobCreateTime(internshipExperience.getJobCreateTime());
        internshipSql.setJobEndTime(internshipExperience.getJobEndTime());
        internshipSql.setJobContent(internshipExperience.getJobContent());
        internshipSql.setJobSkills(internshipExperience.getJobSkills());//拥有技能


        int internshipUpdate = internshipExperienceMapper.updateById(internshipSql);
        if (internshipUpdate>0){
            return ServerResponse.success("internshipExperience表修改成功",null);
        }
        return ServerResponse.fail("internshipExperience表修改失败",null);
    }
}
